from typing import get_origin, Union, get_args


def is_optional_type(cls: type):
    if get_origin(cls) is not Union:
        return False
    args = get_args(cls)
    return len(args) == 2 and args[1] is type(None)


def is_named_tuple(cls: type):
    if not isinstance(cls, type):
        return False
    return issubclass(cls, tuple) and hasattr(cls, '__annotations__')
